const CryptoJS = require('crypto-js'); //引用AES源码js
class secretAES {
    constructor() {
        // 加密
        this.encryptionAES = (params) => {
            let keys = '',
                encryptorStr = '';
            keys = CryptoJS.enc.Utf8.parse('c56d7bab3d6ac01ad9dc6a897652f2d2');
            // keys = CryptoJS.enc.Utf8.parse(sessionStorage.getItem('aesKey')); //动态获取
            params = CryptoJS.enc.Utf8.parse(params);
            // 开始加密
            encryptorStr = CryptoJS.AES.encrypt(
                params,
                keys, {
                    mode: CryptoJS.mode.ECB,
                    padding: CryptoJS.pad.Pkcs7
                }
            );
            encryptorStr = String(encryptorStr); //之将加密后的转换成 字符串, 解密成功
            //返回 加密后的 字符串
            return encryptorStr;
        }

        // 解密
        this.decryptAES = (params) => {
            let keys = '',
                decryptStr = '';
            keys = CryptoJS.enc.Utf8.parse("c56d7bab3d6ac01ad9dc6a897652f2d2");
            // 开始解密
            decryptStr = CryptoJS.AES.decrypt(
                params,
                keys, {
                    mode: CryptoJS.mode.ECB,
                    padding: CryptoJS.pad.Pkcs7
                }
            );
            decryptStr = CryptoJS.enc.Utf8.stringify(decryptStr).toString();
            //返回 解密后的 字符串
            return decryptStr;
        }
    }
}

export default secretAES;